<?php
    require './config/config.php';
	if($_POST){
		$user=$_POST['user'];
		$password=$_POST['password'];
		$repassword=$_POST['repassword'];
		$email=$_POST['email'];
		if(empty($user) or empty($password) or empty($repassword) or empty($email)){
			echo "<script>alert('账号/密码/重复密码/邮箱不能为空！');location='./register.php';</script>";
		}else if($password <> $repassword){
		    echo "<script>alert('两次输入密码不一致，请重试！');location='./register.php';</script>";
		}else{
		    //判断用户名是否重复（是否被占用）
			$sql="select * from member where user='".$user."'";
            $result = mysqli_query($con,$sql);  //返回一个记录集
            $num = mysqli_num_rows($result);
			if($num){
			    echo "<script>alert('此账号已被其他人注册，请更换后再次尝试吧！');location='./register.php';</script>";
			}else{
			    $result = mysqli_query($con,"INSERT INTO `member` (`id`, `user`, `password`, `email`, `state`, `type`, `regtime`) VALUES ('', '".$user."', '".MD5($password)."', '".$email."', '1', '0', '".date("Y/m/d H:i:s")."')");
                if($result){
                   echo "<script>alert('恭喜，喜提账号一枚，快来登录吧！');location='./login.php';</script>";
                }
                else{
                    echo "<script>alert('注册失败，请重试！');location='./register.php';</script>";
                }
			}
		}
	}
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	<link rel="stylesheet" type="text/css" href="css/login.css" />
		 <link rel="stylesheet" href="css/head.css" />
		<link rel="stylesheet" type="text/css" href="css/login.css" />
	</head>

	<body>
<div class="dvhead">
	<div class="dvlogo"><a href="index.php">校园服务反馈系统</a></div>
	<div class="dvreg">
		已有账号，立即&nbsp;<a href="./login.php">登录</a>
	</div>
</div>
		<section class="sec">
		<form action="./register.php" method="post">
			<div class="register-box">
				<label for="username" class="username_label">
					用 户 名
					<input maxlength="20" name="user" type="text"
						placeholder="您的用户名和登录名" />
				</label>
				<div class="tips">

				</div>
			</div>
			<div class="register-box">
				<label for="username" class="other_label">
					设 置 密 码
					<input maxlength="20" type="password" name="password"
						placeholder="建议至少使用两种字符组合" />
				</label>
				<div class="tips">

				</div>
			</div>
			<div class="register-box">
				<label for="username" class="other_label">
					确 认 密 码
					<input maxlength="20" name="repassword" type="password" placeholder="请再次输入密码" />
				</label>
				<div class="tips">

				</div>
			</div>
			
			<div class="register-box">
				<label for="username" class="username_label">
					邮箱
					<input maxlength="20" name="email" type="email"	placeholder="您的邮箱" />
				</label>
				<div class="tips">
				</div>
			</div>
			<div class="submit_btn">
				<button type="submit" id="submit_btn">立 即 注 册</button>
			</div>
		</form>
		</section>
		<script src="js/index.js" type="text/javascript" charset="utf-8"></script>
	</body>
</html>
